import {
	CHECKREAD
} from './mutation_type'

import axios from 'axios'
var isLast = false;
export default {
	updateMessage({
		commit,
		state
	}) {
        var d = "sessionid="+userInfo.sessionid+"&userid="+userInfo.userid+"&page="+state.page+"&pagesize="+state.pagesize
        if (isLast) {
            toast("没有啦！");
            return
        }
        axios.post(userInfo.hosturl + '/IOSApi/ajaxMessage', d, {
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
		}).then(function (data) {
			var data = data.data;
			if (data.result == 0) {
				if (!data.data) {
                    isLast = true;
					return
				}
				var l = data.data.length;
				for (var i = 0; i < l; i++) {
					var newTime = data.data[i].createtime_pst.trim().slice(5, -3);
					data.data[i].createtime_pst = newTime;
				}
				state.messageList.push(...data.data);
				commit(CHECKREAD)
			} else if (data.result == 1037) {
				loginout(1)
			} else {
				toast(data.error)
			}
		}).catch(function(error){
            console.log(error);
            toast(error)
       });
	},
}
